<template>
  <headers />
  <router-view></router-view>
  <footers />
</template>

<script setup>
  import { getUserInfo, getUserInfoByLogin } from "@/api/home.js";
  import headers from "@/components/header/header.vue";
  import footers from "@/components/footer/footer.vue";
  import { onBeforeMount } from "vue";

  onBeforeMount(() => {
    getuserloge();
  });
  const getuserinfor = () => {
    getUserInfo().then((res) => {
      let usercenter = "https://www.icve.com.cn" + res.url;

      localStorage.setItem("usercenter", usercenter);
      localStorage.setItem("username", (res && res.username) || "");
    });
  };
  const getuserloge = () => {
    getUserInfoByLogin().then((res) => {
      if (res.code == -1) {
        localStorage.removeItem("userType");
        localStorage.removeItem("username");
        localStorage.removeItem("logCode");
        localStorage.setItem("logCode", res.code);
      } else {
        getuserinfor();
        let user = JSON.parse(res.loginInfo);
        localStorage.setItem("userType", user.loginInfo[0].userType);
        localStorage.setItem("logCode", res.code);
      }
    });
  };
</script>

<style lang="scss" scoped></style>
